package com.durian.ui.adapter.multi;

import android.content.Context;
import androidx.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;


/**
 * 说明：ViewProvider
 * <p/>
 * 作者：fanly
 * <p/>
 * 类型：Class
 * <p/>
 * 时间：2019-11-06 15:51
 * <p/>
 * 版本：version 1.0
 */
public abstract class ViewProvider<C> {

    private OnItemClickListener<C> mItemClickListener;
    private OnItemLongClickListener<C> mItemLongClickListener;

    protected MultiTypeAdapter mAdapter;

    public void bindAdapter(MultiTypeAdapter adapter) {
        this.mAdapter = adapter;
    }

    @NonNull
    protected abstract MultiItemViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent);

    protected abstract void convert(@NonNull MultiItemViewHolder holder, @NonNull C item, int position);

    protected abstract int getItemLayoutId();

    /**
     * 处理多种类型
     *
     * @return
     */
    protected abstract boolean isMultiType();
    protected abstract Class withLinker(C item);
    protected abstract ArrayList<ViewProvider> getAllMultiViewProviders();


    protected View getItemView(Context context){
        return null;
    }

    /**
     * 设置点击事件
     *
     * @param listener
     */
    public ViewProvider<C> setOnItemClickListener(OnItemClickListener<C> listener) {
        if (listener != null) {
            mItemClickListener = listener;
        }
        return this;
    }

    public OnItemClickListener<C> getOnItemClickListener(){
        return mItemClickListener;
    }

    /**
     * 设置长点击事件
     *
     * @param listener
     */
    public ViewProvider<C> setOnItemLongClickListener(OnItemLongClickListener<C> listener) {
        if (listener != null) {
            mItemLongClickListener = listener;
        }
        return this;
    }

    public OnItemLongClickListener<C> getOnItemLongClickListener(){
        return mItemLongClickListener;
    }

    public void onDestroy() { }

}
